
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;


import entities.userName;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author hungxp
 */
public class loginDao {

    ConnectDB myConn = new ConnectDB();
    Connection conn;
    String acc = null;
    String roles = null;

    public userName checkLogin(String user, String pass) {
        userName use = null;
        String sql = "select *from userName where account='" + user + "' and pass='" + pass + "'";
        try {
            conn = myConn.getConnect();
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            while (rs.next()) {
                use = new userName();
                use.setAccount(rs.getString(2));
                use.setPass(rs.getString(3));
                use.setRoles(rs.getString(4));
                use.setFullName(rs.getString(5));
                use.setBirtday(rs.getString(6));
                use.setGender(rs.getString(7));
                use.setAddress(rs.getString(8));
                use.setEmail(rs.getString(9));
                use.setPhone(rs.getString(10));
            }
        } catch (Exception e) {
        }
        return use;

    }

    public boolean checktk(String user) {        
        boolean kt=false;
        String sql = "select *from userName where account='" + user + "'";
        try {
            conn = myConn.getConnect();
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            while (rs.next()) {
                kt=true;
            }
        } catch (Exception e) {
        }
        return kt;
    }
}
